﻿using System.Collections.Generic;
using System.Windows.Forms;

namespace GeekShop
{
    public partial class MenuManager : Form
    {
        #region Fields
        private List<MenuParent> menuParents = new List<MenuParent>();
        #endregion

        #region Properties
        public List<MenuParent> MenuParents
        {
            get { return menuParents; }
            set { menuParents = value; }
        }
        public MenuStrip MenuStrip
        {
            get { return this.menuStrip; }
            set { this.menuStrip = value; }
        }
        public ToolStripPanel ToolStripPanel
        {
            get { return this.toolStripPanel; }
            set { this.toolStripPanel = value; }
        }
        public override ContextMenuStrip ContextMenuStrip
        {
            get { return this.contextMenu; }
            set { this.contextMenu = value; }
        }
        #endregion

        #region Constructors
        public MenuManager()
        {
            InitializeComponent();
            this.toolStripPanel.Controls.Clear();
        }
        #endregion

        #region Public Methods
        public void Add(MenuParent menuParent)
        {
            int x = 3, y = 3;
            foreach (MenuParent parent in this.menuParents)
            {
                if (parent.ShowAsToolBar)
                {
                    x += parent.StripItem.Width;
                }
            }

            this.menuParents.Add(menuParent);
            this.menuStrip.Items.Add(menuParent.MenuItem);
            this.toolStripPanel.Join(menuParent.StripItem, x, y);
            this.contextMenu.Items.Add(menuParent.ContextItem);
        }
        #endregion
    }
}
